const app=new Vue({
  el:'#app',
  data:{
    books:[
      {
        id:1,
        name:'《海贼王》',
        date:'1996-9',
        price:999,
        count:1
      },
      {
        id:2,
        name:'《overlord》',
        date:'2006-3',
        price:29,
        count:1
      },
      {
        id:3,
        name:'《火影忍者》',
        date:'1996-9',
        price:459,
        count:1
      },
      {
        id:4,
        name:'《妖精的尾巴》',
        date:'2000-9',
        price:200,
        count:1
      },
    ],
  },
  filters:{
    showprice(price){
      return '￥'+ price.toFixed(2)
    }
  },
  methods:{
    incre(index){
      this.books[index].count++
    },
    decre(index){
      this.books[index].count--
    },
    removehandler(index){
      this.books.splice(index,1)
    }
    },
  computed:{
    // totalprice(){
    //   let result=0;
    //   for (let book of this.books){//必须用“of”
    //     result+=book.count*book.price
    //   }
    //   return result
    totalprice(){

      return this.books.reduce(function (prevalue,n){return n.count*n.price+prevalue},0)

    }
  },
    })



